﻿using System;
using System.Drawing;
using RRRSRoguelike.Enums;
using RRRSRoguelike.Helpers.Visualizer;
using RRRSRoguelike.Managers;

namespace RRRSRoguelike.Screens
{
	/// <summary>
	/// Manages the UI to handle the player being prompted to replay.
	/// </summary>
	class ReplayScreen : Screen
	{
		bool YesNo;
		DungeonScreen ds;

		public ReplayScreen(DungeonScreen ds)
		{
			this.ds = ds;

			PanelList.Add(new Panel(new Point(4, 3),
					Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));
		}

		/// <summary>
		/// Calls Show and returns true on Yes and false on No.  Oh! That rhymes. neat.
		/// </summary>
		/// <returns></returns>
		public bool ShowYesNo()
		{
			YesNo = false;

			Show();

			return YesNo;
		}

		public override void Show()
		{
			Clear();



			foreach (Panel p in PanelList)
			{
				p.Clear();
				p.Draw();
			}

			//prompt user
			PanelList[0].Write(Properties.Strings.Replay + Properties.Strings.YNQuestion);

			bool replay;
			ConsoleKey answer;

			//read keyboard
			answer = Console.ReadKey(true).Key;

			//is y pressed?
			replay = answer == ConsoleKey.Y;

			//if y is pressed start game
			if (replay)
			{
				YesNo = true;

				PanelList[0].Write(Properties.Strings.Replay + " " +
								   DungeonManager.Instance.Seed.ToString() +
								   Properties.Strings.YNQuestion);

				if (Console.ReadKey(true).Key == ConsoleKey.Y)
				{
					ds.SetSeed(DungeonManager.Instance.Seed);

					GameManager.Instance.ScreenStack.Push(ds);
				}
				else
				{
					GameManager.Instance.ScreenStack.Push(ds);
				}

			}
			else if (answer != ConsoleKey.N)
			{
				//only n can quit, no accidental quit.
				Show();
			}
			else
			{
				//If no replay move to High Score Screen        
				//GameManager.Instance.ScreenStack.Push(new HighScoreScreen());
			}

			GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
			Clear();
		}
	}
}
